
const quickyContent = {

    //快捷回复分组名修改
    modify(id,replys_group,user_id,callback){
        this.public('/admin/quickreply/edit',{
            id:id,
            replys_group:replys_group || '',
            user_id:user_id
        },callback);
    },

    //快捷回复的内容修改
    modifyContent(id,content,user_id,callback){
            this.public('/admin/quickreply/edit',{
                id:id,
                content:content,
                user_id:user_id
            },callback);
    },


    //快捷回复添加分组
    addContent: function (user_id, replys_group, callback) {
        this.public('/admin/quickreply/save', {
            user_id: user_id,                //客服id
            replys_group: replys_group,      //分组名
        }, callback);

    },


    //快捷回复每个分组中添加内容
    addReplyContent:function(user_id,group_id,content,callback){
        this.public('/admin/quickreply/add',{
            user_id:user_id,
            group_id:group_id,
            content:content
        },callback);
    },


    //快捷回复的展示
    Exhibition: function (newUserId,callback) {
        this.public('/admin/quickreply/index',{
            user_id:newUserId
        },callback);
    },

    //快捷回复的删除
    deleteExhibit:function(id,user_id,callback){
        this.public('/admin/quickreply/del',{
            id:id,
            user_id:user_id
        },callback);
    },


    //公共的方法
    public: function (methods, data, success, error) {
        let xhr = new XMLHttpRequest();
        let formData = new FormData();
        for (let key in data) {
            formData.append(key, data[key]);
        }
        formData.append("authkey", localStorage.getItem("authkey"));
        formData.append("sessionid", localStorage.getItem("sessionid"));

        xhr.open("post", process.env.API_URL + methods);
        xhr.send(formData);
        xhr.onreadystatechange = function () {
            if (xhr.status === 200) {
                if (xhr.readyState === 4) {
                    let responseData = JSON.parse(xhr.responseText);
                    if (success) success(responseData);
                }
            } else {
                if (errorHandler) {
                    let responseData = JSON.parse(xhr.responseText);
                    if (error) error(responseData);
                } else {
                    alert("请求失败！" + xhr.responseText);
                }
            }
        };
    }
};

export default quickyContent;